#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>

#define W_	20
#define H_	20

int
transpose(int a[H_][W_], const int row, const int col, const int size)
{
	register int i, j, t;

	for (i = 0; i < size; ++i)
		if (i > 0)
			for (j = 0; j - i < 0; ++j) {
				t = a[i + row][j + col];
				a[i + row][j + col] = a[j + row][i + col];
				a[j + row][i + col] = t;
			}

	return 0;
}

int
main(int argc, char **argv)
{
	static int a[H_][W_], n, m, k;
	int i, j;
	int r, c, s;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; ++i)
		for (j = 0; j < m; ++j)
			scanf("%d", &a[i][j]);
	scanf("%d", &k);

	for (i = 0; i < k; i++) {
		scanf("%d%d%d", &r, &c, &s);
		transpose(a, r, c, s);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++)
			printf(" %d", a[i][j]);
		fputc('\n', stdout);
	}

	return 0;
}
